package com.hl.shifangzhiyu.web;

import com.hl.shifangzhiyu.pojo.Consultants;
import com.hl.shifangzhiyu.service.ConsultantsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consultant")
public class ConsultantsController {
    @Autowired
    private ConsultantsService consultantsService;
    @RequestMapping("/list/{consultant_id}")
//    @PathVariable:
//这是 Spring MVC 提供的一个注解
//用于指示 Spring 从 URI 模板变量中获取值并绑定到方法参数
//在 RESTful 风格的 URL 设计中非常常用
//Long consultant_id:
//Long 是 Java 的基本数据类型 long 的包装类，表示一个长整型数值
//consultant_id 是方法参数名，用于接收从 URL 路径中提取的值
//整体作用:
//这个组合表示从 URL 路径中提取名为 consultant_id 的变量值
//并将这个值转换为 Long 类型，赋值给方法的 consultant_id 参数
    public Consultants getById(@PathVariable Long consultant_id) {
        return consultantsService.selectByPrimaryKey(consultant_id);
    }





    @RequestMapping("/filter")
    public List<Consultants> filterConsultants(@RequestBody FilterRequest request) {
        return consultantsService.getConsultantsByFilters(request.getTags(), request.getLevel(), request.getSex());
    }

    static class FilterRequest {
        private List<String> tags;
        private String level;
        private String sex;

        // Getters and Setters

        public List<String> getTags() {
            return tags;
        }

        public void setTags(List<String> tags) {
            this.tags = tags;
        }

        public String getLevel() {
            return level;
        }

        public void setLevel(String level) {
            this.level = level;
        }

        public String getSex() {
            return sex;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }
    }


}
